package com.sxu.demo.reentrantlock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * 可重入
 */
public class Test {
    // 获取ReentrantLock对象
    private static ReentrantLock reentrantLock = new ReentrantLock();
    public static void main(String[] args) {
        reentrantLock.lock();
        try {
            System.out.println("main");
            m1();
        } finally {
            reentrantLock.unlock();
        }
    }
    public static void m1(){
        reentrantLock.lock();
        try {
            System.out.println("m1");
            m2();
        } finally {
            reentrantLock.unlock();
        }
    }
    public static void m2(){
        reentrantLock.lock();
        try {
            System.out.println("m2");
        } finally {
            reentrantLock.unlock();
        }
    }
}
